<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java 引用传递深度解析</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .code-container {
            background: linear-gradient(135deg, #1e1e2e 0%, #2d2d44 100%);
            border-radius: 16px;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
            position: relative;
            overflow: hidden;
        }
        .code-container::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 40px;
            background: rgba(255, 255, 255, 0.05);
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }
        .code-dots {
            position: absolute;
            top: 14px;
            left: 20px;
            display: flex;
            gap: 8px;
        }
        .dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
        }
        pre {
            margin: 0;
            padding: 60px 30px 30px;
            overflow-x: auto;
        }
        code {
            color: #e6e6e6;
            font-size: 14px;
            line-height: 1.8;
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
        }
        .keyword { color: #c678dd; }
        .string { color: #98c379; }
        .method { color: #61afef; }
        .class { color: #e06c75; }
        .comment { color: #5c6370; font-style: italic; }
        .hover-card {
            transition: all 0.3s ease;
            cursor: pointer;
        }
        .hover-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
        }
        .concept-card {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            border-radius: 12px;
            padding: 24px;
            position: relative;
            overflow: hidden;
        }
        .concept-card::before {
            content: '';
            position: absolute;
            top: -50%;
            right: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255, 255, 255, 0.3) 0%, transparent 70%);
            transform: rotate(45deg);
        }
        @keyframes float {
            0%, 100% { transform: translateY(0px); }
            50% { transform: translateY(-10px); }
        }
        .float-animation {
            animation: float 3s ease-in-out infinite;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="relative overflow-hidden bg-gradient-to-br from-purple-900 via-purple-700 to-indigo-800 text-white">
        <div class="absolute inset-0 bg-black opacity-20"></div>
        <div class="relative container mx-auto px-6 py-24">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 serif-font">
                    <span class="block mb-2">Java 引用传递</span>
                    <span class="text-3xl md:text-4xl font-light">深入理解对象引用机制</span>
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">
                    探索 Java 中最容易被误解的概念之一
                </p>
                <div class="flex justify-center space-x-4">
                    <div class="bg-white bg-opacity-20 backdrop-blur-sm rounded-full px-6 py-3 flex items-center space-x-2">
                        <i class="fas fa-code"></i>
                        <span>核心概念</span>
                    </div>
                    <div class="bg-white bg-opacity-20 backdrop-blur-sm rounded-full px-6 py-3 flex items-center space-x-2">
                        <i class="fas fa-lightbulb"></i>
                        <span>实例解析</span>
                    </div>
                </div>
            </div>
        </div>
        <div class="absolute bottom-0 left-0 right-0">
            <svg viewBox="0 0 1440 120" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M0 120L60 110C120 100 240 80 360 70C480 60 600 60 720 65C840 70 960 80 1080 85C1200 90 1320 90 1380 90L1440 90V120H1380C1320 120 1200 120 1080 120C960 120 840 120 720 120C600 120 480 120 360 120C240 120 120 120 60 120H0V120Z" fill="#F9FAFB"/>
            </svg>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-16 max-w-6xl">
        <!-- Code Example Section -->
        <section class="mb-16">
            <div class="text-center mb-12">
                <h2 class="text-4xl font-bold mb-4 gradient-text">代码示例</h2>
                <p class="text-gray-600 text-lg">通过实际代码理解引用传递的本质</p>
            </div>
            
            <div class="code-container hover-card">
                <div class="code-dots">
                    <div class="dot bg-red-500"></div>
                    <div class="dot bg-yellow-500"></div>
                    <div class="dot bg-green-500"></div>
                </div>
                <pre><code><span class="keyword">public static void</span> <span class="method">main</span>(<span class="class">String</span>[] args) {
    <span class="class">StringBuffer</span> sf = <span class="keyword">new</span> <span class="class">StringBuffer</span>(<span class="string">"hi,"</span>);
    <span class="method">changeSf</span>(sf);
    <span class="class">System</span>.out.<span class="method">println</span>(sf);
}

<span class="keyword">public static void</span> <span class="method">changeSf</span>(<span class="class">StringBuffer</span> sf) {
    sf.<span class="method">append</span>(<span class="string">"zhangsan"</span>);
}</code></pre>
            </div>
            
            <div class="mt-8 bg-gradient-to-r from-purple-100 to-indigo-100 rounded-lg p-6 border-l-4 border-purple-600">
                <div class="flex items-start space-x-3">
                    <i class="fas fa-terminal text-purple-600 text-2xl mt-1"></i>
                    <div>
                        <h3 class="font-bold text-lg mb-2">运行结果</h3>
                        <p class="text-gray-700 font-mono bg-white rounded px-3 py-2 inline-block">hi,zhangsan</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Visual Explanation -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-center">引用传递机制可视化</h2>
            <div class="mermaid">
                graph LR
                    A[main方法] -->|创建| B[StringBuffer对象<br/>'hi,']
                    A -->|传递引用| C[changeSf方法]
                    C -->|操作同一对象| B
                    B -->|append| D[StringBuffer对象<br/>'hi,zhangsan']
                    style A fill:#667eea,stroke:#333,stroke-width:2px,color:#fff
                    style C fill:#764ba2,stroke:#333,stroke-width:2px,color:#fff
                    style B fill:#98c379,stroke:#333,stroke-width:2px
                    style D fill:#61afef,stroke:#333,stroke-width:2px
            </div>
        </section>

        <!-- Key Concepts -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-center">核心概念解析</h2>
            <div class="grid md:grid-cols-3 gap-6">
                <div class="concept-card hover-card">
                    <div class="relative z-10">
                        <div class="text-4xl mb-4 text-purple-600">
                            <i class="fas fa-link"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-3">引用传递</h3>
                        <p class="text-gray-700">Java 中对象作为参数传递时，传递的是对象引用的副本，而不是对象本身。</p>
                    </div>
                </div>
                
                <div class="concept-card hover-card">
                    <div class="relative z-10">
                        <div class="text-4xl mb-4 text-indigo-600">
                            <i class="fas fa-memory"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-3">内存地址</h3>
                        <p class="text-gray-700">StringBuffer 对象存储在堆内存中，变量 sf 存储的是指向该对象的内存地址。</p>
                    </div>
                </div>
                
                <div class="concept-card hover-card">
                    <div class="relative z-10">
                        <div class="text-4xl mb-4 text-blue-600">
                            <i class="fas fa-sync-alt"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-3">共享对象</h3>
                        <p class="text-gray-700">方法内外的引用指向同一个对象，因此方法内的修改会影响原对象。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Deep Dive -->
        <section class="mb-16">
            <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12">
                <h2 class="text-3xl font-bold mb-6 flex items-center">
                    <i class="fas fa-microscope mr-3 text-purple-600"></i>
                    深入理解
                </h2>
                
                <div class="space-y-6 text-gray-700">
                    <div class="flex items-start space-x-4">
                        <div class="flex-shrink-0 w-8 h-8 bg-purple-100 rounded-full flex items-center justify-center text-purple-600 font-bold">1</div>
                        <div>
                            <h3 class="font-bold mb-2">创建对象</h3>
                            <p>当执行 <code class="bg-gray-100 px-2 py-1 rounded">new StringBuffer("hi,")</code> 时，JVM 在堆内存中创建一个 StringBuffer 对象，并返回该对象的引用地址。</p>
                        </div>
                    </div>
                    
                    <div class="flex items-start space-x-4">
                        <div class="flex-shrink-0 w-8 h-8 bg-purple-100 rounded-full flex items-center justify-center text-purple-600 font-bold">2</div>
                        <div>
                            <h3 class="font-bold mb-2">传递引用</h3>
                            <p>调用 <code class="bg-gray-100 px-2 py-1 rounded">changeSf(sf)</code> 时，传递的是引用的副本。方法参数 sf 和 main 方法中的 sf 指向同一个对象。</p>
                        </div>
                    </div>
                    
                    <div class="flex items-start space-x-4">
                        <div class="flex-shrink-0 w-8 h-8 bg-purple-100 rounded-full flex items-center justify-center text-purple-600 font-bold">3</div>
                        <div>
                            <h3 class="font-bold mb-2">修改对象</h3>
                            <p>在 changeSf 方法中调用 <code class="bg-gray-100 px-2 py-1 rounded">append("zhangsan")</code>，直接修改了堆内存中的对象内容。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Common Misconceptions -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-center">常见误区</h2>
            <div class="grid md:grid-cols-2 gap-6">
                <div class="bg-red-50 border-l-4 border-red-500 p-6 rounded-lg">
                    <div class="flex items-start space-x-3">
                        <i class